package com.itany.cloud.config;

import com.itany.cloud.exception.FeignException;
import feign.Logger;
import feign.Response;
import feign.Retryer;
import feign.codec.ErrorDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 石小俊
 */
@Configuration
public class FeignConfig {

    @Bean
    public Logger.Level feignLoggerLevel(){
        return Logger.Level.FULL;
    }

    @Bean
    public Retryer myRetryer(){
        // 默认值,表示不重试
        // return Retryer.NEVER_RETRY;
        // 参数一:初始间隔时间
        // 参数二:重试期间最大的间隔时间
        // 参数三:最大的调用次数,调用次数为:初始调用次数+重试次数
        return new Retryer.Default(100,1,3);
    }

    @Bean
    public ErrorDecoder feignErrorDecoder(){
        return new ErrorDecoder() {
            @Override
            public Exception decode(String methodKey, Response response) {
                return new FeignException(response.status(),"统一异常处理");
            }
        };
    }
}
